<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :advOptions="[]"
      :dictMap="dictMap"
      :formOptions="formOptions"
      :outputQueryParams="queryParams"
      :queryParams="queryParams"
      :defaultEventKey="defaultEventKey"
    ></Ht-search-form>

    <!--    <div class="page-label-block">-->
    <!--      <span class="color-block">|</span>-->
    <!--      <span class="page-label-name">-->
    <!--      租户管理-->
    <!--      </span>-->
    <!--    </div>-->

    <ht-table
      :defaultEventKey="defaultEventKey"
      ref="dataTable"
      :dictMap="dictMap"
      :multi-select="false"
      :opButtonList="opButtonList"
      :queryParams="queryParams"
      :reqConfig="regConfig"
      :showSerialNumber="false"
      :tableBindColumns="tableBindColumns"
    >
      <template v-slot:operate>
        <el-table-column align="left" fixed="right" label="操作" width="50">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      center
      :visible.sync="open"
      v-if="open"
      append-to-body
      width="1024px"
    >
      <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="160px">
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="交易流水号" prop="id">
              <el-input v-model="detailForm.id" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="工作日期" prop="workdate">
              <el-date-picker
                v-model="detailForm.workdate"
                style="width: 100%"
                type="date"
                value-format="yyyyMMdd"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="CPG日期" prop="vdate">
              <el-date-picker
                v-model="detailForm.vdate"
                style="width: 100%"
                type="date"
                value-format="yyyyMMdd"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="发起直接参与机构" prop="directSender">
              <el-input v-model="detailForm.directSender" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="系统编号" prop="sysCode">
              <el-select style="width: 100%" v-model="detailForm.sysCode" placeholder="系统编号" :disabled="true">
                <el-option
                  v-for="dict in dictMap.SYS_CODE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="原发起直接参与机构" prop="oriDirectSender">
              <el-input v-model="detailForm.oriDirectSender" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="原发起直接参与机构名称" prop="oriDirectSenderName">
              <el-input v-model="detailForm.oriDirectSenderName" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="原报文标识号" prop="oriPkgId">
              <el-input v-model="detailForm.oriPkgId" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="原报文类型代码" prop="oriMsgType">
              <el-select
                style="width: 100%"
                v-model="
                  detailForm.oriMsgType === null || detailForm.oriMsgType === undefined
                    ? ''
                    : detailForm.oriMsgType + '-' + detailForm.oriMsgTypeDesc
                "
                placeholder="原报文类型代码"
                :disabled="true"
              ></el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="业务状态" prop="status1">
              <el-select style="width: 100%" v-model="detailForm.status1" placeholder="业务状态" :disabled="true">
                <el-option
                  v-for="dict in dictMap.CP2_STATUS"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="通讯状态" prop="status2">
              <el-select style="width: 100%" v-model="detailForm.status2" placeholder="通讯状态" :disabled="true">
                <el-option
                  v-for="dict in dictMap.PKG_STATUS"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="附言" prop="remark">
              <el-input type="textarea" v-model="detailForm.remark" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="录入操作员" prop="mdTlrno">
              <el-input v-model="detailForm.mdTlrno" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="录入时间" prop="mdTime">
              <el-date-picker
                style="width: 100%"
                v-model="detailForm.mdTime"
                value-format="yyyyMMddHHmmss"
                type="datetime"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="审核附言" prop="audRemarks">
              <el-input type="textarea" v-model="detailForm.audRemarks" maxlength="128" show-word-limit />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" align="center" class="dialog-footer">
        <el-button type="primary" @click="approve" v-loading.fullscreen.lock="loading">审 核</el-button>
        <el-button type="primary" @click="reject" v-loading.fullscreen.lock="loading">拒 绝</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  apiUrlConfigApproveQuery,
  bepsBusinessCorrectApproveApprove,
  bepsBusinessCorrectApproveDetail,
  bepsBusinessCorrectApproveReject,
} from "@/api/cnaps/beps/413";
import { listPageMixin } from "@/libs/listPageMixin";
import HtAmountInput from "@/views/components/HtAmountInput";
export default {
  name: "bepsBusinessCorrectApprove",
  mixins: [listPageMixin],
  components: { HtAmountInput },
  data() {
    return {
      defaultEventKey: "defaultEventKey",
      loading: false,
      // 查询参数
      queryParams: {
        cpgdate: "",
        cpgdate2: "",
        workdate: "",
        workdate2: "",
        idSeqNo: "",
      },

      // 搜索
      formOptions: [],
      //
      searchFormDictList: ["PKG_TYPE", "CP2_STATUS", "SYS_CODE", "PKG_STATUS"],
      // 列信息
      regConfig: apiUrlConfigApproveQuery,

      rules: {
        audRemarks: [{ max: 128, message: "长度不超过128位", trigger: "blur" }],
      },

      tableBindColumns: [
        { prop: "id", label: "交易流水号", width: 180 },
        { prop: "workdate", label: "工作日期", type: "date" },
        { prop: "vdate", label: "CPG日期", type: "date" },
        { prop: "directSender", label: "发起直接参与机构", width: 150 },
        { prop: "directRecver", label: "接收直接参与机构", width: 150 },
        { prop: "pkgType", label: "报文类型", dictCode: "PKG_TYPE", width: 240 },
        { prop: "status", label: "业务状态", dictCode: "CP2_STATUS" },
        { prop: "mdTlrno", label: "录入操作员", sortable: false },
        { prop: "mdTime", label: "录入时间", type: "date", width: 180 },
      ],

      dictMapAsync: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      openDetail: false,
      // 表单参数
      detailForm: {
        pkgNo: undefined,
        pkgNoDesc: undefined,
      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,
    };
  },
  mounted() {
    const formOptions = [
      // 普通搜索
      {
        type: "dates",
        nameObj: {
          startTimeName: "workdate1",
          endTimeName: "workdate2",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作开始日期", "请输入工作结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },

      {
        type: "dates",
        nameObj: {
          startTimeName: "cpgdate1",
          endTimeName: "cpgdate2",
        },
        defaultAttr: {
          size: "small",
          label: "CPG日期",
          placeholder: ["请输入CPG开始日期", "请输入CPG结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },



      {
        type: "input",
        prop: "idSeqNo",
        defaultAttr: {
          size: "small",
          label: "交易流水号",
          placeholder: "请输入交易流水号",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    /** 搜索按钮操作 */
    handleQuery() {
      this.$refs.dataTable.doQuery(true);
    },

    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      bepsBusinessCorrectApproveDetail(row.id).then((response) => {
        this.title = "业务冲正申请审核明细";
        this.detailForm = response.result;
        this.open = true;
      });
    },

    //审核通过按钮
    approve() {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          this.loading = true;
          bepsBusinessCorrectApproveApprove(this.detailForm)
            .then((response) => {
              this.msgSuccess("审核通过");
              this.open = false;
              this.loading = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
    //审核拒绝按钮
    reject() {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          this.loading = true;
          bepsBusinessCorrectApproveReject(this.detailForm)
            .then((response) => {
              this.msgSuccess("审核拒绝");
              this.open = false;
              this.loading = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
  },
};
</script>
